using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//面板管理器，用栈存储UI
public class PanelManager
{
    //存储UI面板的栈
	private Stack<BasePanel>stackPanel;
    //UI管理器
    private UIManager uiManager;
    private BasePanel panel;

    public PanelManager()
    {
        stackPanel = new Stack<BasePanel>();
        uiManager = new UIManager();
    }
    //UI的入栈操作，显示一个面板
    public void Push(BasePanel nextPanel)
    {
        if(stackPanel.Count > 0)
        {
            //获取栈顶
            panel = stackPanel.Peek();
            panel.OnPause();
        }
        stackPanel.Push(nextPanel);
        GameObject panelGo = uiManager.GetSingleUI(nextPanel.UIType);
        //初始化面板
        nextPanel.Initialize(new UITool(panelGo));
        nextPanel.Initialize(this);
        nextPanel.OnEnter();
    }

    //执行面板出栈操作，此操作执行面板的OnExit方法
    public void Pop()
    {
        if(stackPanel.Count>0)
        {
         	stackPanel.Peek().OnExit();
            stackPanel.Pop();
        }
        if(stackPanel.Count>0)
            stackPanel.Peek().OnResume();
    }
}

